﻿<%@ Page validateRequest="false" Title="" Language="C#" MasterPageFile="~/MasterPage/Site.Master" AutoEventWireup="true" CodeBehind="EditSession.aspx.cs" Inherits="BEELab.EditSession" %>
<%@ Import Namespace="System.Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script>
        function popitup(link) {
            var w = window.open(link,
                  "_blank",
                  'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=auto,resizable=yes,dependent,width=' + screen.width * 0.8 + ',height=' + screen.height * 0.8 + ',left=0,top=0');
            if (w == null) {
                window.location.href = link;
            }

            return false;
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentBody" runat="server">
    <div id="wrap" class="clearfix">
        
        <asp:Label ID="lblEdit" runat="server" Visible="true">
            <a id="btnBack" runat="server" class="back-btn" href="#" onserverclick="BackToExperiment_Click">Back</a>
            <h2 class="headline">Edit Session</h2>
        </asp:Label>

        <div class="sign-form">
            <div class="input-hold">
                <asp:Label ID="Label1" CssClass="sign-label" AssociatedControlID="txtName" runat="server">Name</asp:Label>
                <asp:TextBox CssClass="sign-input" ID="txtName" runat="server" Width="200px"></asp:TextBox>
                <asp:RequiredFieldValidator ValidationGroup="SessionGroup" ID="rfvtxtName" ForeColor="Red" Text="*" ControlToValidate="txtName" runat="server" ErrorMessage="* Name is required."></asp:RequiredFieldValidator>
            </div>

            <div class="input-hold">

                <asp:Label ID="Label2" CssClass="sign-label" AssociatedControlID="txtDescription" runat="server">Description</asp:Label>
                <asp:TextBox CssClass="text-area" ID="txtDescription" runat="server" TextMode="MultiLine"></asp:TextBox>
                <asp:RequiredFieldValidator ValidationGroup="SessionGroup" ID="rfvtxtDescription" ForeColor="Red" Text="*" ControlToValidate="txtDescription" runat="server" ErrorMessage="* Description is required."></asp:RequiredFieldValidator>
            </div>

            <div class="input-hold">
                <div>
                    <label>Status:</label>
                    <asp:Label ID="lblStatus" runat="server"></asp:Label>
                    <asp:LinkButton ID="lnkActive" runat="server" Text="-Activate-" Visible="true" OnClick="lnkActive_Click"></asp:LinkButton>
                    <asp:LinkButton ID="lnkdeactive" runat="server" Text="-Deactivate-"  Visible="true" OnClick="lnkdeactive_Click"></asp:LinkButton>
                    <asp:Literal ID="LiveDataLink" runat="server"></asp:Literal>
                </div>
            </div>

            <p><strong>Initial Variable Values:</strong></p>
            <div class="input-hold">
                <asp:Repeater runat="server" ID="rptSessionVariable" OnItemDataBound="rptSessionVariable_ItemDataBound">
                    <ItemTemplate>
                        <div class="sessionhold">
                            <asp:Label class="sign-label2" ID="lblName" AssociatedControlID="txtVariable" runat="server"><%# ((DataRowView)Container.DataItem)["Name"] + " (Scope:" + ((DataRowView)Container.DataItem)["Scope"] + ")" %> </asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="txtVariable" runat="server" Text=''></asp:TextBox>
                            <asp:Label runat="server" ID="lblVariableId" Visible="false" Text='<%#: ((DataRowView)Container.DataItem)["ID"]%>'></asp:Label>
                            <asp:Label runat="server" ID="lblOldValue" Visible="false" Text=""></asp:Label>
                            <asp:RequiredFieldValidator ValidationGroup="SessionGroup" ID="RequiredFieldValidator2" ForeColor="Red" ControlToValidate="txtVariable" runat="server" ErrorMessage="* Variable Value is required."></asp:RequiredFieldValidator>
                        </div>
                    </ItemTemplate>
                </asp:Repeater>

                <asp:Label ID="lblSessionID" Visible="false" runat="server"></asp:Label>
            </div>

            <div class="input-hold">
                <asp:Button CssClass="sign-submit" ID="btnSubmit" Text="Submit" runat="server" ValidationGroup="SessionGroup" OnClick="btnSubmit_Click" />
            </div>
        </div>
        <div class="error">
            <asp:ValidationSummary ID="vsSession" runat="server" ValidationGroup="SessionGroup" />
            <p>&nbsp</p>
        </div>

        <div class="clr"></div>
        <div class="dashboard-hold">
            <div class="block">
                <h3>Session Data</h3>
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" CssClass="dash-col" OnRowDataBound="GridView1_RowDataBound">
                    <Columns>
                    </Columns>
                </asp:GridView>

            </div>
            <div class="input-hold">
                <br />
                <asp:Button ID="btnExportCSV" CssClass="sign-submit" runat="server" Text="Download Data" OnClick="btnExportCSV_Click"/>
            </div>
        </div>

        <div class="dashboard-hold">
            <div class="block">
                <h3>Invitations</h3>
                <a href="#new-experimentinvi" id="newInvitation" class="abbtn fancybox">New Invitation</a>
                <div id="new-experimentinvi" style="width: 640px; padding: 24px; border: 1px solid #ddd; display: none;">
                    <h2 class="headline">New Invitation</h2>
                    <div class="sign-form">
                        <div class="input-hold">
                            <asp:Label ID="Label3" CssClass="sign-label" AssociatedControlID="TextBox1" runat="server">Name</asp:Label>
                            <asp:TextBox CssClass="sign-input" ID="TextBox1" runat="server" Width="200px"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="Red" ValidationGroup="Invitaion" ControlToValidate="TextBox1" runat="server" ErrorMessage="* Name is required" Text="*"></asp:RequiredFieldValidator>
                        </div>

                        <div class="input-hold">
                            <asp:Button runat="server" ID="Button1" Text="Submit" CssClass="sign-submit" ValidationGroup="Invitaion" OnClick="Button1_Click" />
                        </div>
                    </div>
                    <div class="error">
                        <asp:ValidationSummary ID="vsInvitation" runat="server" ValidationGroup="Invitaion" />
                        <p>&nbsp</p>
                    </div>
                    


                </div>

                <asp:GridView ID="gvInvitation" DataKeyNames="ID" runat="server" AutoGenerateColumns="False" CssClass="dash-col" DataSourceID="SqlDataSource2">
                    <Columns>
                        <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
                        <asp:BoundField DataField="Code" HeaderText="Code" SortExpression="Code" />
                        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" Visible="False" />
                        <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="EditInvitation.aspx?ID={0}" Text="Edit" />
                        <asp:ButtonField CommandName="Delete" Text="Delete" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:beelabConnectionString %>" DeleteCommand="DELETE FROM Invitations WHERE ID=@ID; DELETE FROM InitialValues WHERE Type='Invitation' AND ParentID=@ID" ProviderName="System.Data.SqlClient" SelectCommand="SELECT [Name], [Code], [ID] FROM [Invitations] WHERE ([SessionID] = @SessionID)">
                    <DeleteParameters>
                        <asp:ControlParameter ControlID="gvInvitation" Name="ID" PropertyName="SelectedValue" />
                    </DeleteParameters>
                    <SelectParameters>
                        <asp:QueryStringParameter Name="SessionID" QueryStringField="ID" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        $(document).ready(function () {
            $("a[class='abbtn fancybox']").fancybox();
            $('a[href*="EditInvitation.aspx?ID="]').fancybox({ 'type': 'iframe', 'width': '705px' });

            $('a').filter(function (index) { return $(this).text() === "Delete"; }).click(function () { return confirm('Are you sure you want to delete this item?'); })
        });

    </script>
</asp:Content>
